/*
 * Copyright 2020- 2024. 如志愿 Inc. <https://www.ruzhiyuan.com/>
 * 掌如科技（成都）有限公司
 */

package com.weyoung.common.enums;

import lombok.Getter;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;


/**
 * @author Elliot Lee
 */
@Getter
public enum ResponseCodeEnum {

    SUCCESS(200, "成功"),
    FAIL(500, "失败"),;

    final Integer code;

    final String desc;

    ResponseCodeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static Map<Integer, String> toMap() {
        Map<Integer, String> map = new HashMap<>(16);
        for (ResponseCodeEnum element : values()) {
            map.put(element.getCode(), element.getDesc());
        }
        return map;
    }

    public static ResponseCodeEnum getByCode(Integer code) {
        for (ResponseCodeEnum element : values()) {
            if (code.equals(element.getCode())) {
                return element;
            }
        }
        return null;
    }

    public static Set<Integer> allowableValues() {
        Set<Integer> allowableValues = new HashSet<>(values().length);
        for (ResponseCodeEnum orderTypeEnum : values()) {
            allowableValues.add(orderTypeEnum.getCode());
        }
        return allowableValues;
    }

}
